<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>广告列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
    <h1>广告列表</h1>
    <a href="/admin/ads/add" class="btn btn-primary mb-3">添加广告</a>
    <a href="/admin/categories" class="btn btn-secondary mb-3">分类管理</a>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>分类</th>
            <th>图片</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="ad : ${ads}">
            <td th:text="${ad.id}"></td>
            <td th:text="${ad.name}"></td>
            <td th:text="${ad.categoryName}"></td>
            <td>

                <img th:if="${ad.imageUrl}" th:src="@{|http://localhost:8081${ad.imageUrl}|}" width="100" alt="广告图片">
            </td>
            <td>
                <span th:if="${ad.status == 1}" class="badge bg-success">启用</span>
                <span th:if="${ad.status == 0}" class="badge bg-danger">禁用</span>
            </td>
            <td>
                <a th:href="@{/admin/ads/edit/{id}(id=${ad.id})}" class="btn btn-sm btn-warning">编辑</a>
                <a th:href="@{/admin/ads/delete/{id}(id=${ad.id})}" class="btn btn-sm btn-danger" onclick="return confirm('确定删除吗？')">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>